<template>
  <main role="main">
    <div class="album py-5 bg-light">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <pagination ref="pagination" v-bind:list="listCourse"></pagination>
          </div>
        </div>
        <br>
        <div class="row">
          <div v-for="o in courses" class="col-md-3">
            <the-course v-bind:course="o"></the-course>
          </div>
          <h3 v-show="courses.length === 0">未找到课程</h3>
        </div>
      </div>
    </div>

  </main>
</template>

<script>
  import TheCourse from "../components/the-course";
  import Pagination from "../components/pagination";
  import  {mapState,mapMutations} from 'vuex'
  export default {
    components: {Pagination, TheCourse},
    name: 'searchTieba',
    data: function () {
      return {
        courses: [],
        searchMsg:''
      }
    },
    created(){
      // console.log('aaa')
      this.searchMsg =  this.$route.params.searchMsg;
    },
    computed:{
      ...mapState([
        'ifsearch'
      ])
    },
    watch:{
      ifsearch(){
        // console.log('变化=====')
        this.searchMsg =  this.$route.params.searchMsg;
        let _this = this;
        _this.$refs.pagination.size = 3;
        _this.listCourse(1);
      }
    },
    mounted() {
             let _this = this;
          _this.$refs.pagination.size = 3;
          _this.listCourse(1);
   
    },
    methods: {
      ...mapMutations([
        'setifsearch'
      ]),
      /**
       * 查询课程列表
       */
      listCourse(page) {
        let _this = this;
        _this.$ajax.post(process.env.VUE_APP_SERVER + '/business/web/course/list', {
          page: page,
          size: _this.$refs.pagination.size,
          // categoryId: _this.level2Id || _this.level1Id || "", // 优先取level2Id
          searchMsg:_this.searchMsg,
        }).then((response) => {
          let resp = response.data;
          if (resp.success) {
            _this.courses = resp.content.list;
            _this.$refs.pagination.render(page, resp.content.total);
          }
        }).catch((response) => {
          console.log("error：", response);
        })
      },

    }
  }
</script>
<style>
  /* 头部 一级分类 */
  .header-nav {
    height: auto;
    background: #fff;
    box-shadow: 0 8px 16px 0 rgba(28,31,33,.1);
    padding: 16px 0;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
    /*background-color: #d6e9c6;*/
  }
  .header-nav>div {
    width: 100%;
    padding-left: 12px;
    box-sizing: border-box;
    margin-left: auto;
    margin-right: auto;
    /*background-color: #B4D5AC;*/
  }
  .header-nav a {
    float: left;
    font-size: 16px;
    color: #07111b;
    line-height: 50px;
    height: 45px;
    position: relative;
    margin-right: 46px;
    font-weight: 700;
  }
  .header-nav a:hover {
    color: #c80;
  }
  .header-nav a.cur {
    color: #c80;
  }
  .header-nav a.cur:before {
    display: block;
  }
  .header-nav a:before {
    display: none;
    content: ' ';
    position: absolute;
    bottom: 0;
    background: #c80;
    width: 16px;
    height: 3px;
    left: 50%;
    margin-left: -8px;
  }
  /* 二级分类 */
  .skill {
    width: 100%;
    padding: 24px 0 0;
    position: relative;
    margin: 0 auto;
  }
  .skill a.on {
    color: #c80;
    background: rgba(204,136,0,.1);
  }
  .skill a {
    float: left;
    margin-right: 20px;
    padding: 0 12px;
    font-size: 14px;
    color: #4d555d;
    line-height: 32px;
    border-radius: 6px;
    margin-bottom: 12px;
  }
  .skill a:hover {
    background: #d9dde1;
  }
</style>
